package com.ticket.sass.admin.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.annotation.Loggable;
import com.ticket.sass.admin.annotation.Module;
import com.ticket.sass.admin.business.PriceSchemeBusiness;
import com.ticket.sass.admin.dto.input.pricescheme.PriceSchemeAddInput;
import com.ticket.sass.admin.dto.input.pricescheme.PriceSchemeListInput;
import com.ticket.sass.admin.dto.input.pricescheme.PriceSchemeUpdInput;
import com.ticket.sass.admin.dto.output.pricecheme.PriceSchemeListOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ywb
 * @since 2024-03-06
 */
@RestController
@AllArgsConstructor
@ApiSupport(order = 18)
@Api(tags = {"票价方案模块-模块"})
@RequestMapping("/price-schemes")
public class PriceSchemeController {
   
    final PriceSchemeBusiness business;
   
    @ApiOperation("列表")
    @GetMapping
    public ResultModel<PageModel<PriceSchemeListOutput>> list(
        @Valid PriceSchemeListInput input
    ) {
        return ResultModel.success(
            business.list(input)
        );
    }
    
    @ApiOperation("新增")
    @PostMapping
    @Loggable(module = Module.PRICE_SCHEME, desc = "新增")
    public ResultModel<String> add(
        @RequestBody @Valid PriceSchemeAddInput input
    ) {
        business.add(input);
        return ResultModel.success();
    }
    
    @ApiOperation("修改")
    @PutMapping
    @Loggable(module = Module.PRICE_SCHEME, desc = "修改")
    public ResultModel<String> upd(
        @RequestBody @Valid PriceSchemeUpdInput input
    ) {
        business.upd(input);
        return ResultModel.success();
    }
}
